﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WordNet.Core;
using WordNet.Core.ElementContracts;
using WordNet.Core.DataContract;

namespace WordNet.CoreTests.Parsers
{
    [TestClass]
    public class UnitTestIndexLineVerb:UnitTestBase
    {
        const string VERB_LINE = "dog v 1 2 @ ~ 1 1 01983615";
       
        [ClassInitialize]
        public static void ClassInit(TestContext context)
        {
            Container = MEFLoader.Load();
        }
        
        [TestMethod]
        public void CanParseVerb()
        {
            IParser<IIndexWord> indexLineParser = Container.GetExportedValue<IParser<IIndexWord>>();
            IIndexWord indexWord = indexLineParser.Parse(VERB_LINE);
            Assert.IsNotNull(indexWord);

        }

        [TestMethod]
        public void CanParseLemmaVerb()
        {
            IParser<IIndexWord> indexLineParser = Container.GetExportedValue<IParser<IIndexWord>>();
            IIndexWord indexWord = indexLineParser.Parse(VERB_LINE);
            Assert.IsNotNull(indexWord);
            string expectedLemma = "dog";
            Assert.AreEqual(expectedLemma, indexWord.Lemma);

        }

        [TestMethod]
        public void CanParseSyntacticCategoryVerb()
        {
            IParser<IIndexWord> indexLineParser = Container.GetExportedValue<IParser<IIndexWord>>();
            IIndexWord indexWord = indexLineParser.Parse(VERB_LINE);
            Assert.IsNotNull(indexWord);
            POS expectedPOS = POS.VERB;

            Assert.AreEqual(expectedPOS, indexWord.PartOfSpeech);

        }

        [TestMethod]
        public void CanParsePointersVerb()
        {
            IParser<IIndexWord> indexLineParser = Container.GetExportedValue<IParser<IIndexWord>>();
            IIndexWord indexWord = indexLineParser.Parse(VERB_LINE);
            Assert.IsNotNull(indexWord);
            int expected_pointer_count = 2;
            Assert.AreEqual(expected_pointer_count, indexWord.GetPointers().Count);
            Assert.IsTrue(indexWord.GetPointers().Contains(Pointer.GetPointerType("@", POS.VERB)));
            Assert.IsTrue(indexWord.GetPointers().Contains(Pointer.GetPointerType("~", POS.VERB)));


            Assert.IsFalse(indexWord.GetPointers().Contains(Pointer.GetPointerType("#s", POS.VERB)));
        }

        [TestMethod]
        public void CanParseTagSenseCountVerb()
        {
            IParser<IIndexWord> indexLineParser = Container.GetExportedValue<IParser<IIndexWord>>();
            IIndexWord indexWord = indexLineParser.Parse(VERB_LINE);
            int expectedTagSenseCount = 1;
            Assert.AreEqual(expectedTagSenseCount, indexWord.TagSenseCount);
        }

        [TestMethod]
        public void CanParseSynsetOffsetVerb()
        {
            IParser<IIndexWord> indexLineParser = Container.GetExportedValue<IParser<IIndexWord>>();
            IIndexWord indexWord = indexLineParser.Parse(VERB_LINE);
            int expectedOffsetCount = 1;
            Assert.AreEqual(expectedOffsetCount, indexWord.GetWordIDs().Count);
            foreach (var wordId in indexWord.GetWordIDs())
            {
                Assert.AreEqual("dog", wordId.Lemma);
                Assert.AreEqual(POS.VERB, wordId.PartOfSpeech);
            }
            Assert.AreEqual(int.Parse("01983615"), indexWord.GetWordIDs()[0].SynsetID.Offset);
            Assert.AreEqual(POS.VERB, indexWord.GetWordIDs()[0].SynsetID.PartOfSpeech);


        }
    }
}
